<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div id="div1" class="box" title="div1"></div>
    <div id="div2" class="box" title="div2"></div>
    <button class="btn" data-target="div1" data-taday-is-a-good-day="ok">点击</button>
    <script>
        // 点击变色效果  自定义属性取值   对象.dataset.属性
        var btn = document.querySelector('.btn');
        btn.onclick = function () {
            // 获取要操作的div
            var targetValue = this.dataset.target;
            targetValue = '#' + targetValue;
            var targeEl = document.querySelector(targetValue);
            targeEl.style.backgroundColor = 'pink';
            // 复杂类型的自定义属性，需要转换驼峰
            console.log(btn.dataset.tadayIsAGoodDay);
            console.log(btn.dataset['tadayIsAGoodDay']);
        }
    </script>
</body>
</html>